/**
 * 
 *汇付天下有限公司
 * Copyright (c) 2006-2014 ChinaPnR,Inc.All Rights Reserved.
 */
package com.loser.csp.service.backmanager.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.loser.csp.dal.dao.CategoryMapper;
import com.loser.csp.dal.model.Category;
import com.loser.csp.service.backmanager.CategoryServices;
import com.loser.csp.service.backmanager.enums.MessageCodeEnum;
import com.loser.csp.service.backmanager.exception.BackManagerException;

/**
 * 
 * @author jun.li
 * @version $Id: CategoryServicesImpl.java, v 0.1 2014-2-24 下午12:59:39 jun.li Exp $
 */
@Component("categoryServices")
public class CategoryServicesImpl implements CategoryServices {
    @Autowired
    private CategoryMapper categoryMapper;

    @Override
    public int insert(Category category) {
        if (category == null) {
            throw new BackManagerException(MessageCodeEnum.ADD_CATEGORY_PARAMETER_NULL.getCode());
        }
        return categoryMapper.insert(category);
    }

    @Override
    public Category selectById(int categoryId) {        
        return categoryMapper.selectByCategoryid(categoryId);
    }

    @Override
    public int deleteById(int categoryId) {
        
        return categoryMapper.deleteByCategoryid(categoryId);
    }

    @Override
    public int updateById(Category category) {
        if (category == null) {
            throw new BackManagerException(MessageCodeEnum.UPDATE_CATEGORY_PARAMETER_NULL.getCode());
        }
        return categoryMapper.updateByPrimarys(category);
    }

}
